package pshycomanagement

class ViewresultController {
    def index = {
        redirect(action: "viewresult")
    }
    def viewresult = {  
        def result1 = ["","","",""]
        def resultT = [0,0,0,0]
        def resultF = [0,0,0,0]
        def letters = ["E","S","T","J"]
        def letters2 = ["I","N","F","P"]
        def answers = ["","","",""]
        
        for (i in 0..3){
            
            result1[i] = Question.findAllByTypeAndState1("${letters[i]}",true)
            resultT[i] = result1[i].size()
            result1[i] = Question.findAllByTypeAndState1("${letters[i]}",false)
            resultF[i] = result1[i].size()
            
            if (resultT[i]>resultF[i]){
                answers[i]= "${letters[i]}"
            }
            else {
                answers[i]= "${letters2[i]}"
            }
        }
        [state:result1,state2:resultT,state:resultF,answer:answers]
    }
}